package com.example.myapplication.slice;


import com.example.myapplication.ResourceTable;
import com.example.myapplication.beans.Contacts;
import com.example.myapplication.constant.Constant;
import com.example.myapplication.utils.ToastUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;

public class ContactsDetailSlice extends AbilitySlice {
    private Text nameText, genderText, phoneText;
    private Image leftImage;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_slice_contacts_detail);
        initView();
        //接收上一个页面传递过来的数据
        Contacts contacts = (Contacts) intent.getSerializableParam("contacts");
        if (contacts != null) {
//            ToastUtil.showToast(this,"name="+contacts.getName());
            nameText.setText(contacts.getName());
            if (contacts.getGender() == Constant.GENDER_MAN) {
                genderText.setText(Constant.GENDER_MAN_STRING);
            } else {
                genderText.setText(Constant.GENDER_LADY_STRING);
            }
            phoneText.setText(contacts.getPhone());
        }

    }

    private void initView() {
        nameText = (Text) findComponentById(ResourceTable.Id_text_name);
        genderText = (Text) findComponentById(ResourceTable.Id_text_gender);
        phoneText = (Text) findComponentById(ResourceTable.Id_text_phone);
        leftImage = (Image) findComponentById(ResourceTable.Id_image_left);
        //左侧箭头的返回按钮，设置点击事件，并且调用系统的返回方法
        leftImage.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                ToastUtil.showToast(ContactsDetailSlice.this, "onclick");
                ContactsDetailSlice.this.onBackPressed();
            }
        });
    }
}
